#include <stdio.h>
#include <atmi.h>
#include <fml32.h>
#include <Usysfl32.h>
#include <tpadm.h>

main(int argc, char *argv[])
{
	int	ret;
	char	connected_node[1024];

	if (tpinit((TPINIT *) NULL) == -1) {
		(void) printf("Tpinit failed[%s]\n", tpstrerror(tperrno));
		exit(1);
	}

	/* ----------------------------- */
	ret = tpgettuxnodename(connected_node);

	if (!ret)
		printf("- ret:%d, node_name : %s\n", ret, connected_node);
	/* ----------------------------- */

	tpterm();
}

int tpgettuxnodename( char *node_name )
{
	FBFR32 	*sendbuf, *rcvbuf;
	long	len;
	long 	occurs;
	int 	i;
	
	if((sendbuf = (FBFR32 *)tpalloc("FML32", NULL, 1024)) == NULL) {
		printf("tpalloc error : %s\n", tpstrerror(tperrno));
		exit(1);
	}
	if((rcvbuf = (FBFR32 *)tpalloc("FML32", NULL, 1024)) == NULL) {
		printf("tpalloc error : %s\n", tpstrerror(tperrno));
		tpfree((char *)sendbuf);
		exit(1);
	}

	Finit32(sendbuf, Fsizeof32(sendbuf));
	Finit32(rcvbuf, Fsizeof32(rcvbuf));
	Fchg32(sendbuf, TA_OPERATION, 	0, "GET", 0);
	Fchg32(sendbuf, TA_CLASS, 	0, "T_MACHINE", 0);

	if(tpcall(".TMIB", (char *)sendbuf, 0, (char **)&rcvbuf, &len, TPNOTRAN|TPNOCHANGE|TPSIGRSTRT|TPNOTIME) == -1) {
		printf("tpcall failed: %s\n", tpstrerror(tperrno));
		return(tperrno);
	}

	Fget32(rcvbuf, TA_OCCURS, 0, (char *)&occurs, 0);

	for(i = 0; i < occurs; i++) {
		Fget32(rcvbuf, TA_PMID, 	i, node_name, 0);
	}

	tpfree((char *)sendbuf);
	tpfree((char *)rcvbuf);

	return(0);
}

